#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

ll qmi(ll a, ll b)
{
    ll res = 1;
    while(b)
    {
        res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res;
}

void solve()
{
    int n;
    cin >> n;
    int st1 = 0;
    int x, ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        if(x % 3 == 1) st1 = 1;
        ans += x;
    }
    if(ans % 3 == 0)
    {
        cout << 0 << endl;
    }
    else if(ans % 3 == 2)
    {
        cout << 1 << endl;
    }
    else if(st1 && ans % 3 == 1)
        cout << 1 << endl;
    else cout << 2 << endl;

}

int main()
{
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}